<?php
/*
Bitsand - a web-based booking system for LRP events
Copyright (C) 2006, 2007 Russell Peter Phillips

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

//Do not check that user is logged in
$bLoginCheck = False;

//Initialise $CSS_PREFIX
$CSS_PREFIX = '../';

//Load required inc files
include ($CSS_PREFIX . 'inc/inc_head_db.php');
include ($CSS_PREFIX . 'inc/inc_head_html.php');
?>

<h1>Create Tables with Prefixes</h1>

<p>
This page will create a set of tables, with prefixes, as defined in the configuration file. It will report progress as it goes. Note that, in order for this to work, the user defined in the configuration file must have permission to create and drop tables in the specified database. To use it, enter the value of CRYPT_KEY from the configuration file and click &quot;Create Tables&quot;.
</p>

<p>
<i>This has not been extensively tested. Use at your own risk. If you find a bug, please file a bug report at <a href = "http://code.google.com/p/bitsand/issues/list">http://code.google.com/p/bitsand/issues/list</a></i>.

<form action = "create_tables.php" method = "post">
<p>
Value of CRYPT_KEY in configuration file: <input name = "txtKey"><br>
<input type = "submit" value = "Create Tables" name = "btnSubmit">
</p>
</form>

<p>
<?php
if ($_POST ['btnSubmit'] != '' && $_POST ['txtKey'] == CRYPT_KEY) {
	echo "Creating table: " . DB_PREFIX . "access_log<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "access_log`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "access_log` (`alID` int(11) NOT NULL auto_increment, `alDateTime` timestamp NOT NULL default CURRENT_TIMESTAMP, `alPlayerID` int(11) NOT NULL COMMENT 'This will be zero if the user is not logged in', `alIP` tinytext NOT NULL, `alPage` text NOT NULL, `alGet` text NOT NULL, `alePost` blob NOT NULL COMMENT 'Encrypted', PRIMARY KEY  (`alID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1");
	echo "Table created: " . DB_PREFIX . "access_log<br>\n";

	echo "Creating table: " . DB_PREFIX . "bookings<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "bookings`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "bookings` (`bkID` int(11) NOT NULL auto_increment, `bkPlayerID` int(11) NOT NULL, `bkDateOOCConfirmed` date NOT NULL, `bkDateICConfirmed` date NOT NULL, `bkDatePaymentConfirmed` date NOT NULL, `bkMealTicket` binary(1) NOT NULL, PRIMARY KEY  (`bkID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1");
	echo "Table created: " . DB_PREFIX . "bookings<br>\n";

	echo "Creating table: " . DB_PREFIX . "characters<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "characters`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "characters` (`chCharacterID` int(11) NOT NULL auto_increment, `chPlayerID` int(11) NOT NULL default '0', `chName` text NOT NULL, `chRace` text NOT NULL, `chGender` enum('Female','Male') NOT NULL default 'Male', `chGroupSel` text NOT NULL, `chGroupText` text NOT NULL, `chFaction` text NOT NULL, `chAncestor` text NOT NULL, `chLocation` text NOT NULL, `chNPC` tinyint(1) NOT NULL default '0', `chNotes` text NOT NULL, `chOSP` text NOT NULL, PRIMARY KEY  (`chCharacterID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1");
	echo "Table created: " . DB_PREFIX . "characters<br>\n";

	echo "Creating table: " . DB_PREFIX . "factions<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "factions`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "factions` (`faID` tinyint(4) NOT NULL default '0', `faName` text NOT NULL, PRIMARY KEY  (`faID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1");
	ba_db_query ($link, "INSERT INTO `" . DB_PREFIX . "factions` (`faID`, `faName`) VALUES (1, 'Bears'),(2, 'Dragons'),(3, 'Gryphons'),(4, 'Harts'),(5, 'Jackals'),(6, 'Lions'),(7, 'Tarantulas'),(8, 'Unicorns'),(9, 'Vipers'),(10, 'Wolves'),(11, 'Non-Faction'),(12, 'Staff')");
	echo "Table created: " . DB_PREFIX . "factions<br>\n";

	echo "Creating table: " . DB_PREFIX . "groups<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "groups`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "groups` (`grID` int(11) NOT NULL, `grName` text NOT NULL, PRIMARY KEY  (`grID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1");
	echo "Table created: " . DB_PREFIX . "groups<br>\n";

	echo "Creating table: " . DB_PREFIX . "guildmembers<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "guildmembers`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "guildmembers` (`gmID` int(11) NOT NULL auto_increment, `gmPlayerID` int(11) NOT NULL, `gmName` text NOT NULL, PRIMARY KEY  (`gmID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1");
	echo "Table created: " . DB_PREFIX . "guildmembers<br>\n";

	echo "Creating table: " . DB_PREFIX . "guilds<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "guilds`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "guilds` (`guID` int(11) NOT NULL, `guName` text NOT NULL, PRIMARY KEY  (`guID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1");
	ba_db_query ($link, "INSERT INTO `" . DB_PREFIX . "guilds` (`guID`, `guName`) VALUES (5, 'Bards'),(8, 'Mages'),(6, 'Healers'),(7, 'Incantors'),(2, 'Alchemists'),(3, 'Archers'),(10, 'Scouts'),(9, 'Militia'),(4, 'Bank'),(1, ' None')");
	echo "Table created: " . DB_PREFIX . "guilds<br>\n";

	echo "Creating table: " . DB_PREFIX . "locations<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "locations`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "locations` (`lnID` tinyint(4) NOT NULL default '0', `lnName` text NOT NULL, PRIMARY KEY  (`lnID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1");
	echo "Table created: " . DB_PREFIX . "locations<br>\n";

	echo "Creating table: " . DB_PREFIX . "players<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "players`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "players` (`plPlayerID` int(11) NOT NULL auto_increment, `plPassword` text NOT NULL, `pleAddress1` blob NOT NULL, `pleAddress2` blob NOT NULL, `pleAddress3` blob NOT NULL, `pleAddress4` blob NOT NULL, `plePostcode` blob NOT NULL, `pleTelephone` blob NOT NULL, `pleMobile` blob NOT NULL, `pleMedicalInfo` blob NOT NULL, `pleEmergencyNumber` blob NOT NULL, `plLoginCounter` tinyint(4) NOT NULL default '0' COMMENT 'Number of times user has tried to log in. Reset to 0 on successful login', `plAccess` text NOT NULL, `plFirstName` text NOT NULL, `plSurname` text NOT NULL, `plEmail` text NOT NULL, `plDOB` text NOT NULL, `plEmergencyName` text NOT NULL, `plEmergencyRelationship` text NOT NULL, `plCarRegistration` text NOT NULL, `plDietary` enum('Omnivore','Vegetarian','Vegan','Other/allergy (details in Medical Information box)') default NULL, `plBookAs` enum('Monster','Player','Staff') default NULL, `plNewMail` text COMMENT 'New e-mail address', `plNewMailCode` tinytext COMMENT 'Code to confirm new e-mail address', `plBunkRequested` binary(1) NOT NULL default '0', `plBunkAssigned` binary(1) NOT NULL default '0', `plNotes` TEXT NULL COMMENT 'General notes', `plAdminNotes` TEXT NULL, PRIMARY KEY  (`plPlayerID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1");
	echo "Table created: " . DB_PREFIX . "players<br>\n";

	echo "Creating table: " . DB_PREFIX . "sessions<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "sessions`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "sessions` (`ssID` int(11) NOT NULL auto_increment, `ssPlayerID` int(11) NOT NULL, `ssLoginTime` text NOT NULL, `ssIP` tinytext NOT NULL, `ssLastAccess` int(11) NOT NULL, PRIMARY KEY  (`ssID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1");
	echo "Table created: " . DB_PREFIX . "sessions<br>\n";

	echo "Creating table: " . DB_PREFIX . "skills<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "skills`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "skills` (`skID` int(11) NOT NULL default '0', `skName` text NOT NULL, `skCost` tinyint(4) NOT NULL default '0', PRIMARY KEY  (`skID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1");
	ba_db_query ($link, "INSERT INTO `" . DB_PREFIX . "skills` (`skID`, `skName`, `skCost`) VALUES (1, 'Ambidexterity', 2),(2, 'Ritual Magic 2', 4),(3, 'Large Melee Weapon Use', 2),(4, 'Ritual Magic 3', 6),(5, 'Projectile Weapon Use', 4),(6, 'Contribute To Ritualist', 1),(7, 'Shield Use', 2),(8, 'Invocation', 3),(9, 'Missile Weapon Use', 1),(10, 'Power 1', 2),(11, 'Body Development 1', 4),(12, 'Power 2', 4),(13, 'Body Development 2', 8),(14, 'Power 3', 6),(15, 'Light Armour Use', 2),(16, 'Power 4', 8),(17, 'Medium Armour Use', 3),(18, 'Potion Lore', 3),(19, 'Heavy Armour Use', 4),(20, 'Poison Lore', 4),(21, 'Healing 1', 4),(22, 'Cartography', 1),(23, 'Healing 2', 8),(24, 'Sense Magic', 1),(25, 'Spellcasting 1', 4),(26, 'Evaluate', 1),(27, 'Spellcasting 2', 8),(28, 'Recognise Forgery', 1),(29, 'Incantations 1', 4),(30, 'Physician', 2),(31, 'Incantations 2', 8),(32, 'Bind Wounds', 1),(33, 'Ritual Magic 1', 2)");
	echo "Table created: " . DB_PREFIX . "skills<br>\n";

	echo "Creating table: " . DB_PREFIX . "skillstaken<br>\n";
	ba_db_query ($link, "DROP TABLE IF EXISTS `" . DB_PREFIX . "skillstaken`");
	ba_db_query ($link, "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "skillstaken` (`stID` int(11) NOT NULL auto_increment, `stPlayerID` int(11) NOT NULL default '0', `stSkillID` tinyint(4) NOT NULL default '0', PRIMARY KEY  (`stID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1");
	echo "Table created: " . DB_PREFIX . "skillstaken<br>\n";
}
elseif ($_POST ['btnSubmit'] != '' && $_POST ['txtKey'] != CRYPT_KEY)
	echo "<span class = 'sans-warn'>Wrong value entered for CRYPT_KEY</span>";
?>
</p>

<p><a href = "./">Installation Tests &amp; Tools</a></p>
<?php
include ('../inc/inc_foot.php');
?>
